package org.jivesoftware.launcher;

import java.io.File;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

class JiveClassLoader extends URLClassLoader
{
	JiveClassLoader(ClassLoader parent, File libDir) throws MalformedURLException
	{
		super(new URL[] {libDir.toURI().toURL()}, parent);
		
		File[] jars = libDir.listFiles(new FilenameFilter() 
		{
			public boolean accept(File dir, String name)
			{
				boolean accept = false;
				String smallName = name.toLowerCase();
				if (smallName.endsWith(".jar"))
				{
					accept = true;
				}
				else if (smallName.endsWith(".zip"))
				{
					accept = true;
				}
				return accept;
			}
		});
		
		if (jars == null)
		{
			return;
		}
		
		for (File jar : jars)
		{
			if (jar.isFile())
			{
				addURL(jar.toURI().toURL());
			}
		}
	}
}
